package club.caihappy.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

/**
 * Created by 百岁 on 2021/9/21
 **/
@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/Login")
    public String login(String username, String password, HttpSession session, Model model) {
        session.setAttribute("userInfo", username);
        System.out.println("login"+session.getAttribute("userInfo"));
        model.addAttribute("username",username);
        return "success";
    }
//注销
    @RequestMapping("/goOut")
    public String goOut(HttpSession session) {
        session.removeAttribute("userInfo");
        System.out.println("goOut"+session.getAttribute("userInfo"));
//        session.invalidate();
        return "success";
    }

    @RequestMapping("/goLogin")
    public String goLogin() {
        return "login";
    }

    @RequestMapping("/goMain")
    public String goMain() {
        return "success";
    }
}
